matrix = [["1","0","1","0","0"],["1","0","1","1","1"],["1","1","1","1","1"],["1","0","0","1","0"]]
def maximalSquare(matrix):
    matrix_row_len=len(matrix)
    matrix_col_len=len(matrix[0])
    dp=[[0 for _ in range(matrix_col_len)] for _ in range(matrix_row_len)]
    print(dp)
    for i in range(matrix_row_len):
        for j in range(matrix_col_len):
            if matrix[i][j]=="1":
                if j==0 or i==0:
                    dp[i][j]=1
                else:
                    dp[i][j]=min(dp[i-1][j],dp[i][j-1],dp[i-1][j-1])+1
    max_value=dp[0][0]
    for i in range(matrix_row_len):
        for j in range(matrix_col_len):
            if max_value<dp[i][j]:
                max_value=dp[i][j]
    print(max_value*max_value)
maximalSquare(matrix)